package com.test;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import com.iamk.util.GetData;
import com.iamk.util.ListFilesUtil;


public class InverseMask {
	public static void main(String[] args) {
		ListFilesUtil lfu = new ListFilesUtil();
		lfu.listAllFiles("C:\\Users\\Ken\\Desktop\\MSRC_binhvt_mask\\MaskTrainSRM\\");
		for(int f = 0; f < lfu.arrAllFile.size();f++){
			System.out.println(lfu.arrFileName.get(f));
			int[][] mask = GetData.readMaskFile(lfu.arrAllFile.get(f));
			saveMask("C:\\Users\\Ken\\Desktop\\MSRC_binhvt_mask\\NewMaskTrainSRM\\" + lfu.arrFileName.get(f).replace(".bmp", "") + ".txt", mask);
		}
	}
	
	public static void saveMask(String path, int[][] mask){
		// Save mask
		File file = new File(path);
		try {
			BufferedWriter bw = new BufferedWriter(new FileWriter(file));
			for (int i = 0; i < mask[0].length; i++) {
				// for each row
				for (int j = 0; j < mask.length; j++) // for each column
				{
					int write = (j == (mask.length - 1)) ? 1 : 0;
					if (write == 1)
						bw.write(mask[j][i] + "");
					else
						bw.write(mask[j][i] + ",");
				}
				bw.write("\n");
			}
			bw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
